﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace DownloadInterface
{
    public enum FileType
    {
        FILE_DOCUMENT,
        FILE_MOVIE,
        FILE_MUSIC,
        FILE_EXECUTEABLE,
        FILE_UNKNOWN
    }
    [Serializable()]
    public class DownloadTask:INotifyPropertyChanged
    {
        public int downloadId { get; set; }

        private string _fileName;
        public string fileName {
            get { return _fileName; }
            set { _fileName = value;
            PropertyChanged(this, new PropertyChangedEventArgs("fileName"));
            } 
        }

        public string fileSize { get; set; }

        public string filePath { get; set; }

        public FileType fileType { get; set; }

        public FileCategory fileCategory { get; set; }

        private string _downloadUrl="";
        public string downloadUrl {
            get { return _downloadUrl; }
            set {  int i = value.Split('/').Count();
                   if(value != null && _downloadUrl != value)
                    fileName = value.Split('/')[i - 1];
                   
                    _downloadUrl = value;
                   PropertyChanged(this, new PropertyChangedEventArgs("downloadUrl"));
                }
        }

        public DateTime finishedTime { get; set; }

        public DownloadStatus taskStatus { get; set; }

        public DownloadTask(string url, string fileName, string filePath, FileCategory fileCategory)
        {
            this._downloadUrl = url;
            this._fileName = fileName;
            this.filePath = filePath;
            this.fileCategory = fileCategory;
            this.taskStatus = new DownloadStatus();
        }

        [field:NonSerialized]public event PropertyChangedEventHandler PropertyChanged;
    }
}
